import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { BookmarkService } from './bookmark.service';
import { CreateBookmarkDto } from './dto/create-bookmark.dto';
import { UpdateBookmarkDto } from './dto/update-bookmark.dto';
import { PageQuery } from '../../../util/entity/page.entity';
import { Role } from '../../admin/role/entities/role.entity';
import { ReqUser } from '../../../common/decorator/user.decorator';

@Controller()
export class BookmarkController {
  constructor(private readonly bookmarkService: BookmarkService) {}

  @Post()
  create(
    @Body() createBookmarkDto: CreateBookmarkDto,
    @ReqUser('id') userId: number,
  ) {
    return this.bookmarkService.create(createBookmarkDto, userId);
  }

  @Post('list')
  findAll(@Body() pageQuery: PageQuery<Role>, @ReqUser('id') userId: number) {
    return this.bookmarkService.findAll(pageQuery, userId);
  }

  @Get(':id')
  findOne(@Param('id') id: number, @ReqUser('id') userId: number) {
    return this.bookmarkService.findOne(id, userId);
  }

  @Patch('count/:id')
  updateCount(@Param('id') id: number, @ReqUser('id') userId: number) {
    return this.bookmarkService.addCount(id, userId);
  }

  @Patch(':id')
  update(
    @Param('id') id: number,
    @Body() updateBookmarkDto: UpdateBookmarkDto,
    @ReqUser('id') userId: number,
  ) {
    return this.bookmarkService.update(id, updateBookmarkDto, userId);
  }

  @Delete(':id')
  remove(@Param('id') id: number, @ReqUser('id') userId: number) {
    return this.bookmarkService.remove(id, userId);
  }
}
